package com.secsys.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggerFactory;

import com.secsys.dto.BbsModuleDTO;
import com.secsys.dto.InitModuleCountInfoDTO;
import com.secsys.dto.ModuleBean;
import com.secsys.model.TbBbsModule;
import com.secsys.service.RoleService;
import com.secsys.service.UserService;
import com.secsys.service.impl.BbsModuleServiceImpl;
import com.secsys.service.impl.PostServiceImpl;
import com.secsys.service.impl.ReplyServiceImpl;
import com.secsys.util.Constant;

public class BbsModuleAction extends BaseAction<BbsModuleDTO> {
	private static final Logger logger = Logger
			.getLogger(BbsModuleAction.class);
	private static final long serialVersionUID = 123456789L;
	private BbsModuleServiceImpl bbsModuleService;
	private String block; // 大模块标志
	private BbsModuleDTO moduleDTO;
	private PostServiceImpl postService;
	private ReplyServiceImpl replyService;

	private RoleService roleService;

	private String title; // 对应模块主题
	private String moduleTh[];
	private String thChildModule[];
    
	public String[] getThChildModule() {
		return thChildModule;
	}

	public void setThChildModule(String[] thChildModule) {
		this.thChildModule = thChildModule;
	}

	public String[] getModuleTh() {
		return moduleTh;
	}

	public void setModuleTh(String[] moduleTh) {
		this.moduleTh = moduleTh;
	}

	private UserService userService;

	public String getBlock() {
		return block;
	}

	@Override
	public BbsModuleDTO getModel() {
		// TODO Auto-generated method stub
		if (moduleDTO == null)
			moduleDTO = new BbsModuleDTO();
		return moduleDTO;
	}

	public String getTitle() {
		return title;
	}

	public void setBbsModuleService(BbsModuleServiceImpl bbsModuleService) {
		this.bbsModuleService = bbsModuleService;
	}

	public void setBlock(String block) {
		this.block = block;
	}

	public void setPostService(PostServiceImpl postService) {
		this.postService = postService;
	}

	public void setReplyService(ReplyServiceImpl replyService) {
		this.replyService = replyService;
	}

	public void setRoleService(RoleService roleService) {
		this.roleService = roleService;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	/**
	 * 
	 * @Description 初始化论坛模块
	 * @return
	 * @throws Exception
	 */
	public String initModule() throws Exception {
		List parentModuleList = bbsModuleService.initModuleInfo(postService,
				roleService, userService, replyService, null, "00");
		InitModuleCountInfoDTO moduleCountInfoDTO = bbsModuleService
				.queryTotalBbsCountInfo(userService, replyService, postService);
		application.put("initModule", parentModuleList); // 初始化各模块信息、参数
		application.put("moduleCountInfoDTO", moduleCountInfoDTO);
		return "index";
	}

	/**
	 * @Description 技术板块跳转
	 * @return
	 */

	public String moduleAnalyse() throws Exception {
		String BLOCK;

		if (block != null) {
			if (block.equals("tech")) {
				BLOCK = Constant.TECH_MODULE_NAME;
			} else if (block.equals("basic")) {
				BLOCK = Constant.BASIC_MODULE_NAME;
			} else if (block.equals("infod")) {
				BLOCK = Constant.TECPLOT_INFOD;
			} else if (block.equals("ssm")) {
				BLOCK = Constant.STATION_SERVICE_MANAGER;
			} else if (block.equals("books")) {
				BLOCK = Constant.BOOKS_DOWNLOAD;

			} else {

				return "index";
			}
			List moduleList = bbsModuleService.initModuleInfo(postService,
					roleService, userService, replyService, BLOCK, null);
			InitModuleCountInfoDTO moduleCountInfoDto = bbsModuleService
					.queryTotalModuleCountInfo(userService, replyService,
							postService, BLOCK);
			application.put("moduleList", moduleList); // 存储到session中
			application.put("BlockModuleCountDto", moduleCountInfoDto);
			return "moduleQuery";
		} else {
			return "index";
		}
	}

	/**
	 * 
	 * @Description 论坛模块信息管理查询
	 * @return
	 * @throws Exception
	 */
	public String queryModuleInfo() throws Exception {

		return "managerModuleInfo";
	}

	/**
	 * 
	 * @Description 子模块跳转
	 * @return
	 * @throws Exception
	 */
	public String titleByModule() throws Exception {
		TbBbsModule tbBbsModule = null;
		BbsModuleDTO moduleDTO = null;
		List postList = null;
		postList = (List) session.get("postList"); // 请求前先获取session
		if (postList != null && postList.size() != 0) { // 假如不为空，或大小不为零则过滤掉历史数据
			session.remove("postList");
		}
		if (block.equals("tech") && title.equals("indt")) {
			tbBbsModule = bbsModuleService.getModule(Constant.INDEX_TECPLOT,
					Constant.MODULE_ABLE); // 获取对应的module子模块
		} else if (block.equals("tech") && title.equals("lineShaple")) {
			tbBbsModule = bbsModuleService.getModule(
					Constant.K_LINE_TANGENT_SHAPE_ANAY, Constant.MODULE_ABLE); // 获取对应的module子模块
		} else if (block.equals("tech") && title.equals("waveTh")) {
			tbBbsModule = bbsModuleService.getModule(
					Constant.WAVE_THEORY_DISCUSS, Constant.MODULE_ABLE); // 获取对应的module子模块
		} else if (block.equals("basic") && title.equals("values")) { // 价值理念大家谈
			tbBbsModule = bbsModuleService.getModule(Constant.VALUES,
					Constant.MODULE_ABLE);
		} else if (block.equals("basic") && title.equals("macroEconomy")) { // 宏观经济
			tbBbsModule = bbsModuleService.getModule(Constant.MACRO_ECONOMICS,
					Constant.MODULE_ABLE);
		} else if (block.equals("basic") && title.equals("researchInstn")) { // 机构...
			tbBbsModule = bbsModuleService.getModule(
					Constant.REPORTING_AGENCIES, Constant.MODULE_ABLE);
		} else if (block.equals("basic") && title.equals("qtCompany")) { // 行情与公司
			tbBbsModule = bbsModuleService.getModule(
					Constant.INDUSTRY_COMPANY_ANALYSIS, Constant.MODULE_ABLE);
		} else if (block.equals("books") && title.equals("book")) { // 书籍下载
		
			tbBbsModule = bbsModuleService.getModule(
					Constant.BOOK_DOWNLOADANDADVICE, Constant.MODULE_ABLE);
		} else if (block.equals("ssm") && title.equals("rookie")) {
			tbBbsModule = bbsModuleService.getModule(Constant.ROOKIE,
					Constant.MODULE_ABLE);
		} else if (block.equals("ssm") && title.equals("complaint")) {
			tbBbsModule = bbsModuleService.getModule(Constant.COMPLAINT,
					Constant.MODULE_ABLE);
		} else {
			return "index";
		}
		moduleDTO = bbsModuleService.getDtoFromBean(tbBbsModule);
		postList = postService.queryPostListInfo(tbBbsModule, replyService);
		session.put("postList", postList);
		session.put("moduleDTO", moduleDTO);
		request.put("block", block);
		request.put("title", title);
		return "postList";
	}

	/**
	 * 
	 * @Description 更新模块信息
	 * @return
	 * @throws Exception
	 */
	public String showModuleInfo() throws Exception {
       
		ModuleBean moduleBean = bbsModuleService.getModuleStatue();
		 
		 session.put("moduleBean", moduleBean);
		request.put("moduleBean", moduleBean);
		 request.put("schildModule", moduleBean.getSchildModule());
		 request.put("smodule", moduleBean.getSmodule());
		return "managerModuleUpdate";
	}

}
